﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;
namespace OracleDAL.Sec
{
   public class UserGroup_UserInfo
    {
        public UserGroup_UserInfo()
        {

        }
        #region  成员方法
      
		/// <summary>
		/// 是否存在该记录
		/// </summary>
        public bool Exists(string strWhere)
        {
            string sql = "select count(1) from SEC_USERGROUP_USERINFO where " + strWhere;
            return OracleHelper.Exists(sql);
        }

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.Sec.UserGroup_UserInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into SEC_USERGROUP_USERINFO(");
			strSql.Append("USERGROUPISN,USERISN)");
			strSql.Append(" values (");
			strSql.Append(":USERGROUPISN,:USERISN)");
			OracleParameter[] parameters = {
					new OracleParameter(":USERGROUPISN", OracleType.VarChar,50),
					new OracleParameter(":USERISN", OracleType.VarChar,50)};
			parameters[0].Value = model.USERGROUPISN;
			parameters[1].Value = model.USERISN;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string USERGROUPISN,string USERISN)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete SEC_USERGROUP_USERINFO ");
			strSql.Append(" where USERGROUPISN=:USERGROUPISN and USERISN=:USERISN ");
			OracleParameter[] parameters = {
					new OracleParameter(":USERGROUPISN", OracleType.VarChar,50),
					new OracleParameter(":USERISN", OracleType.VarChar,50)};
			parameters[0].Value = USERGROUPISN;
			parameters[1].Value = USERISN;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
        public void Delete(string strWhere)
        {
            string sql = "delete SEC_USERGROUP_USERINFO where " + strWhere;
            OracleHelper.ExecuteSql(sql);
        }
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.Sec.UserGroup_UserInfo GetModel(string USERGROUPISN,string USERISN)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select USERGROUPISN,USERISN from SEC_USERGROUP_USERINFO ");
			strSql.Append(" where USERGROUPISN=:USERGROUPISN and USERISN=:USERISN ");
			OracleParameter[] parameters = {
					new OracleParameter(":USERGROUPISN", OracleType.VarChar,50),
					new OracleParameter(":USERISN", OracleType.VarChar,50)};
			parameters[0].Value = USERGROUPISN;
			parameters[1].Value = USERISN;

			Model.Sec.UserGroup_UserInfo model=new Model.Sec.UserGroup_UserInfo();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.USERGROUPISN=ds.Tables[0].Rows[0]["USERGROUPISN"].ToString();
				model.USERISN=ds.Tables[0].Rows[0]["USERISN"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select USERGROUPISN,USERISN ");
			strSql.Append(" FROM SEC_USERGROUP_USERINFO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return OracleHelper.Query(strSql.ToString());
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Sec.UserGroup_UserInfo GetModel(string strWhere)
        {
            Model.Sec.UserGroup_UserInfo uu = new Model.Sec.UserGroup_UserInfo();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select USERGROUPISN,USERISN ");
            strSql.Append(" FROM SEC_USERGROUP_USERINFO ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            OracleDataReader dr = OracleHelper.ExecuteReader(strSql.ToString());
            while (dr.Read())
            {
                uu.USERGROUPISN = dr["USERGROUPISN"].ToString();
                uu.USERISN = dr["USERGROUPISN"].ToString();
            }
            dr.Close();
            dr.Dispose();
            return uu;
        }
       /// <summary>
       /// 根据用户的isn更改其所属用户组
       /// </summary>
       /// <param name="UserGroupISN"></param>
       /// <param name="UserISN"></param>
       /// <returns></returns>
        public bool Update(string UserGroupISN,string UserISN)
        {
            string sql = "update SEC_USERGROUP_USERINFO set USERGROUPISN='" + UserGroupISN + "' where userisn='" + UserISN + "'";
            int rows = OracleHelper.ExecuteSql(sql);
            if (rows > 0)
                return true;
            else
                return false;
        }
        #endregion  成员方法
    }
}
